package com.dreem.principle.inversion.improve;

/**
 * @program: DesignParrtern
 * @description:
 * @author: Peng
 * @create: 2021-01-16  09:58
 **/
public class DependencyInversionUP03 {
    public static void main(String[] args){
        ITV03 tv = new ITV03() {
            @Override
            public void play() {
                System.out.println("CCTV1正在播放！");
            }
        };
        OpenAndClose03 openAndClose03 = new OpenAndClose03();
        openAndClose03.setTV(tv);
        openAndClose03.open();
    }
}

// 方式3：通过setter方法传递
interface IOpenAndClose03{
    public void open();// 抽象方法
    public void setTV(ITV03 tv);
}

interface ITV03 { // ITV接口
    public void play();
}

class OpenAndClose03 implements IOpenAndClose03 {

    private ITV03 tv;

    @Override
    public void open() {
        this.tv.play();
    }
    @Override
    public void setTV(ITV03 tv) {
        this.tv = tv;
    }
}